
import request from './request.ts'
import { getStore } from "@/utils/store";
import { client_id} from '@/const/const'

// 移动回收站
export function dclibRecycle(id){
  return request({
    url: `/mgr/document/dcLibrary/recycle/${id}`,
    method: "delete",
    headers:{
      MessageDcLibraryId:id,
      dcLibraryId:id
    }
  });
}

// 查询常用文档
export function knowledgeFrequently(query) {
  return request({
    url: "/mgr/document/dcLibrary/log/frequently",
    method: "get",
    params: query
  });
}

// 查询用户有权限的知识库
export function getDcLibraryList(query) {
  return request({
    url: "/mgr/document/dcLibrary/knowledges",
    method: "get",
    params: query
  });
}

// 查询用户自己创建的知识库
export function knowledgesOwner(query) {
  return request({
    url: "/mgr/document/dcLibrary/knowledges/owner",
    method: "get",
    params: query
  });
}

// 查询我的收藏
export function knowledgesCollect(query) {
  return request({
    url: "/mgr/document/dcLibrary/collect",
    method: "get",
    params: query
  });
}

// 查询回收站
export function knowledgeRecycle(query) {
  return request({
    url: "/mgr/document/dcLibrary/recycle",
    method: "get",
    params: query
  });
}

// 获取目录树
export function getLibTree(data) {
  let userInfo = getStore({name: 'userInfo'})
  return request({
    url: !userInfo?`/mgr/document/no/auth/tree`:`/mgr/document/dcLibrary/tree`,
    method: "get",
    // params: {id: id}
    params: data,
    headers:{
      documentId:data.id
    }
  });
}

//获取所有文件夹 名称
export function getFilesync(){
  return request({
    url:`/mgr/document/file/sync/get/folder`,
    method:"get"
  })
}
//同步
export function saveFilesync(data){
  return request({
    url:`/mgr/document/file/sync`,
    method:'post',
    data
  })
}
//获取同步日志
export function getsyncPagelog(params){
  return request({
    url:`/mgr/document/file/sync/page/log`,
    method:"get",
    params:params
  })
}

// 获取移动新建文件夹目录树
export function getFileMenuTree(params){
  return request({
    url:'/mgr/document/dcLibrary/tree/folder',
    method:"get",
    params:params
  })
}

// 添加知识库、目录、文件
export function addLibrary(data) {
  return request({
    url:`/mgr/document/dcLibrary`,
    method:'post',
    data: data
  })
}

// 恢复文件
export function dclRetrieve(data){
  return request({
    url:`/mgr/document/dcLibrary/retrieve`,
    method:"post",
    data:data
  })
}

// 彻底删除文件
export const delLib = (data) => {
  return request({
    url: `/mgr/document/dcLibrary/physical/delete`,
    method: 'post',
    data:data
  })
}

// 调整文档位置New
export function locationOther(data) {
  return request({
    url: `/mgr/document/dcLibrary/location/other`,
    method: "put",
    data: data,
    headers:{
      dcLibraryId:data.id
    }
  });
}

// 查询知识库成员
export function getLibMember(id,params) {
  return request({
    url: `/mgr/document/dcLibrary/query/member/${id}`,
    method: "get",
    params: params
  });
}

export function getCommentList(id,data){
  let userInfo = getStore({name: 'userInfo'})
  return request({
    url:userInfo?`/mgr/document/dcLibrary/comment/page/${id}`:`/mgr/document/no/auth/dcLibrary/comment/page/${id}`,
    method:'get',
    params: data
  })
}

// 查询操作日志
export const logPage = (data)=>{
  return request({
    url:`/mgr/document/dcLibrary/log/page`,
    method:'get',
    params:data
  })
}

// 修改文件名
export const changeFileName = (data) =>{
  return request({
    url: '/mgr/document/dcLibrary/update/name',
    method: 'put',
    data:data,
    headers:{
      MessageDcLibraryId:data.id,
      dcLibraryId:data.id
    }
  })
}

// 置顶数据
export const topAdd = (data)=>{
  return request({
    url:`/mgr/document/dc/topping/add`,
    method:'post',
    data
  })
}

// 置顶 取消
export const topCancal = (data)=>{
  return request({
    url:`/mgr/document/dc/topping/update`,
    method:'post',
    data
  })
}

// 文件夹重新排序
export function fileTreeSort(data){
  return request({
    url:`/mgr/document/dcLibrary/reset/sort`,
    method:'post',
    data
  })
}

// 获取常用文库
export function getComUsage(data){
  return request({
    url:`/mgr/document/dcLibrary/log/frequently/knowledge`,
    method:'get',
    data
  })
}

// 文件下载
export function downLoadFile(data , responseType= 'blob'){
  return request({
    url:`/mgr/document/dcLibrary/file/get/file/${data.id}`,
    method:'get',
    responseType: responseType,
    headers:{
      dcLibraryId:data.id
    },
    timeout:pluginConfig.fileDownloadTime
  })
}
// 知识库、文件夹下载
export function downLoadFileD(data, responseType= 'blob'){
  return request({
    url:`/mgr/document/dcLibrary/file/get/folder/${data.id}`,
    method:'get',
    responseType: responseType,
    timeout:pluginConfig.fileDownloadTime
  })
}

// 文件下载
export function fileDown(type,id){
  return request({
    url:`/mgr/document/dcLibrary/file/down/${type}/${id}`,
    method:'get',
    headers:{
      dcLibraryId:id
    },
    timeout:pluginConfig.fileDownloadTime
  })
}
// 文件解压
export const fileDictoryDec = (data)=>{
  return request({
    url:`/mgr/document/dcLibrary/file/zip/${data.id}`,
    method:'post',
    data
  })
}